package com.neusoft.mapper;

import java.sql.Date;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.neusoft.po.VacationPO;
import com.neusoft.po.Vacation_TypePO;
import com.neusoft.vo.SdayVO;
import com.neusoft.vo.VacationVO;
import com.neusoft.vo.VacationVVO;
import com.neusoft.vo.Vacation_TypeVO;
import com.neusoft.vo.VacationagreeVO;
import com.neusoft.vo.Vacationcvo;

public interface VacationMapper {

	//新增假期类型
	@Insert("INSERT INTO vacation_type (vacation_name, limitt) VALUES (#{vacation_name}, #{limitt})")
	public void inertVacation(VacationVVO po);
	//获得假期
	@Select("select last_insert_id();")
	public Integer getid();
	
	@Select("select empno from emp")
	public List<Integer> getempno();
	//更新年假
	@Insert("INSERT INTO available_vacation (vacation_id , empno , year , days ) VALUES (2, #{empno} ,#{year},#{days})")
	public void inertVacation2(Vacation_TypeVO vo);
	//修改假期类型名
	@Update("UPDATE vacation_type SET vacation_name = #{vacation_name} WHERE vacation_id = #{vacation_id}")
	public void updateVacation(Vacationcvo po);
	@Delete("DELETE FROM vacation_type WHERE vacation_id = #{id}")
	public void delateVacation(Integer vacation_id );
	@Insert("INSERT INTO vacation_record (empno, vacation_id,start_date,end_date,duration,vacation_reason,state) VALUES (#{empno}, #{vacation_id},#{start_date},#{end_date},#{duration},#{vacation_reason},-1)")
	public void addVacation(VacationVO po);
	//获取用户的入职日期
	@Select("select work_date from emp where empno=#{empno}")
	public Date getdata(Integer empno);
	//使用受限制假期
	@Update("UPDATE available_vacation SET days = days - #{duration} WHERE empno = #{empno} AND vacation_id= #{vacation_id} ")
	public void upavailable_vacation(VacationagreeVO po);
	//使用年假
	@Update("UPDATE available_vacation SET days = days - 1  WHERE vacation_id = #{vacation_id} AND empno = #{empno} AND days > 0  order by YEAR asc limit 1 ")
	public void upavailable_vacation2(VacationagreeVO po);
	//自动删除过期年假
	@Delete("DELETE FROM available_vacation WHERE year <= #{year} - 2")
	public void delavailable_vacation(Integer year);
	//审批通过
	@Update("UPDATE vacation_record SET state = 1  WHERE record_id = #{record_id} ")
	public void agreeavailable_record(Integer record_id);
	//审批驳回
	@Update("UPDATE vacation_record SET state = 0  WHERE record_id = #{record_id} ")
	public void noavailable_record(Integer record_id);
	//获得所有类型
	@Select("select * FROM vacation_type")
	public List<Vacation_TypePO> getvlist();
	//查询当前用户的名字
	@Select("select ename from emp where empno=#{empno}")
	public String getename(Integer empno);
	//查询当前用户的当前假期的假期类型
	@Select("select vacation_name from vacation_type where vacation_id=#{vacation_id}")
	public String getvname(Integer vacation_id);
	//获取当前用户的假期记录
	@Select("select * FROM vacation_record where empno = #{empno}")
	public List<VacationPO> selectlist(Integer empno);
	//获取当前未审批用户的假期记录
	@Select("select * FROM vacation_record where empno = #{empno} AND state =-1")
	public List<VacationPO> selectlistt(Integer empno);
	//获取当前部门的所有员工的编号
	@Select("select empno from emp where deptno=#{deptno}")
	public List<Integer> getempnon(Integer deptno);
	
	@Select("select SUM(days) from available_vacation where vacation_id=#{vacation_id} AND empno=#{empno}")
	public Integer selectday(SdayVO vo);
	
}
